package com.kasax.ipcbus.corel.marker;

import com.kasax.ipcbus.bean.RequestBean;
import com.kasax.ipcbus.utils.LogUtils;

import java.lang.reflect.Method;

public class ObjectResponseMaker extends ResponseMaker {
    private Object mObject;
    private Method mMethod;

    @Override
    protected Object invokeMethod() {
        try {
            Object obj = mMethod.invoke(mObject, mParameters);
            LogUtils.i(getClass(), "invokeMethod obj: " + obj);
            return obj;
        } catch (Exception e) {
            LogUtils.e(getClass(), e);
        }
        return null;
    }

    @Override
    protected void setMethod(RequestBean requestBean) {
        mObject = OBJ_CENTER.getObject(resultClass.getName());
        Method method = typeCenter.getMethod(mObject.getClass(), requestBean);
        mMethod = method;
    }
}
